
const res = []
let track = []

function backtrack(str) {
  if (track.length == str.length) {
    res.push(track.join());
    return;
  }
  for (let i = 0; i < str.length; i++) {
    if (track.includes(str[i])) {
      continue;
    }

    track.push(str[i]);
    backtrack(str);
    track.pop();
  }
}
backtrack('abcd')
console.log(res)